package com.example.springboot.dao;

import com.example.springboot.entity.Record;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface RecordDao extends Mapper<Record> {

    @Select("select * from record where `id` = #{id}")
    Record findById(@Param("id")Integer id);
    @Select({
            "<script>",
            "SELECT r.*, u.username, a.title AS activityName FROM record r",
            "LEFT JOIN user u ON r.userId = u.id",
            "LEFT JOIN activity a ON r.activityId = a.id",
            "WHERE 1=1",
            "<if test='search.activityId != null'> AND r.activityId = #{search.activityId} </if>",
            "<if test='search.userId != null'> AND r.userId = #{search.userId} </if>",
            "</script>"
    })
    List<Record> findBySearchWithUser(@Param("search") Record search);
    List<Record> findBySearch(@Param("search") Record search,@Param("userId") Integer userId,@Param("role") Integer role);


}